package com.example.experiment3.controller;

import com.example.experiment3.service.CoronaVirusDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import static com.example.experiment3.service.CoronaVirusDataService.sum_1;
import static com.example.experiment3.service.CoronaVirusDataService.sum_2;

@Controller
@RequestMapping("/CoronaVirusData")
public class CoronaVirusDataController {

    @Autowired
    private CoronaVirusDataService coronaVirusDataService;

    @RequestMapping("/getAllRegionStats")
    public String getAllRegionStats(Model model){

        List allList = coronaVirusDataService.getAllRegionStats();
        model.addAttribute("sum_1",sum_1);
        model.addAttribute("sum_2",sum_2);
        model.addAttribute("allList",allList);
        return "index";

    }

    @RequestMapping("/findRegionStatsByKey")
    public String findRegionStatsByKey(String key, Model model){

        List findByKeyList = findByKeyList = coronaVirusDataService.findRegionDataByKey(key);
        model.addAttribute("allList",findByKeyList);
        model.addAttribute("sum_1",sum_1);
        model.addAttribute("sum_2",sum_2);
        return "index";

    }

}
